package me.landery.modules.sinco.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.landery.modules.sinco.service.OrderService;
import me.landery.modules.sinco.service.dto.OrderQueryCriteria;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author cc.w
 * @Date 2022/6/7 15:35
 * @Version 1.0
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "Sinco：订单管理")
@RequestMapping("/sinco/order")
public class OrderController {

    private final OrderService orderService;
    private static final String ENTITY_NAME = "order";

    @ApiOperation("查询订单")
    @GetMapping
    @PreAuthorize("@el.check('order:list','admin')")
    public ResponseEntity<Object> queryOrder(OrderQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(orderService.queryAll(criteria, pageable), HttpStatus.OK);
    }

    @ApiOperation("查询订单")
    @GetMapping("/web")
    @PreAuthorize("@el.check('order:weblist','admin')")
    public ResponseEntity<Object> queryOrderWeb(OrderQueryCriteria criteria, Pageable pageable){
        Pageable pageable1 = PageRequest.of(pageable.getPageNumber()-1,pageable.getPageSize(),pageable.getSort());
        return new ResponseEntity<>(orderService.queryAll(criteria, pageable1), HttpStatus.OK);
    }

}
